﻿﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Xml.Serialization;
using XCode;
using XCode.Configuration;
using XCode.DataAccessLayer;

namespace NewsPub
{
    /// <summary>文章</summary>
    [Serializable]
    [DataObject]
    [Description("文章")]
    [BindIndex("PK__Details__3214EC270CBAE877", true, "ID")]
    [BindIndex("IX_Details_ClassisID", false, "ClassisID")]
    [BindRelation("ClassisID", false, "Classis", "ID")]
    [BindTable("Details", Description = "文章", ConnName = "NewsPub", DbType = DatabaseType.SqlServer)]
    public partial class Details<TEntity> : IDetails
    {
        #region 属性
        private Int32 _ClassisID;
        /// <summary>文章分类</summary>
        [DisplayName("文章分类")]
        [Description("文章分类")]
        [DataObjectField(false, false, true, 10)]
        [BindColumn(1, "ClassisID", "文章分类", null, "int", 10, 0, false)]
        public virtual Int32 ClassisID
        {
            get { return _ClassisID; }
            set { if (OnPropertyChanging(__.ClassisID, value)) { _ClassisID = value; OnPropertyChanged(__.ClassisID); } }
        }

        private Int32 _UserID;
        /// <summary>作者</summary>
        [DisplayName("作者")]
        [Description("作者")]
        [DataObjectField(false, false, true, 10)]
        [BindColumn(2, "UserID", "作者", null, "int", 10, 0, false)]
        public virtual Int32 UserID
        {
            get { return _UserID; }
            set { if (OnPropertyChanging(__.UserID, value)) { _UserID = value; OnPropertyChanged(__.UserID); } }
        }

        private String _Title;
        /// <summary>标题</summary>
        [DisplayName("标题")]
        [Description("标题")]
        [DataObjectField(false, false, false, -1)]
        [BindColumn(3, "Title", "标题", null, "nvarchar(MAX)", 0, 0, true)]
        public virtual String Title
        {
            get { return _Title; }
            set { if (OnPropertyChanging(__.Title, value)) { _Title = value; OnPropertyChanged(__.Title); } }
        }

        private String _Body;
        /// <summary>内容</summary>
        [DisplayName("内容")]
        [Description("内容")]
        [DataObjectField(false, false, false, 1073741823)]
        [BindColumn(4, "Body", "内容", null, "ntext", 0, 0, true)]
        public virtual String Body
        {
            get { return _Body; }
            set { if (OnPropertyChanging(__.Body, value)) { _Body = value; OnPropertyChanged(__.Body); } }
        }

        private String _Tag;
        /// <summary>摘要</summary>
        [DisplayName("摘要")]
        [Description("摘要")]
        [DataObjectField(false, false, false, -1)]
        [BindColumn(5, "Tag", "摘要", null, "nvarchar(MAX)", 0, 0, true)]
        public virtual String Tag
        {
            get { return _Tag; }
            set { if (OnPropertyChanging(__.Tag, value)) { _Tag = value; OnPropertyChanged(__.Tag); } }
        }

        private DateTime _CreateTime;
        /// <summary>发表时间</summary>
        [DisplayName("发表时间")]
        [Description("发表时间")]
        [DataObjectField(false, false, true, 3)]
        [BindColumn(6, "CreateTime", "发表时间", null, "datetime", 3, 0, false)]
        public virtual DateTime CreateTime
        {
            get { return _CreateTime; }
            set { if (OnPropertyChanging(__.CreateTime, value)) { _CreateTime = value; OnPropertyChanged(__.CreateTime); } }
        }

        private DateTime _EditTime;
        /// <summary>编辑时间</summary>
        [DisplayName("编辑时间")]
        [Description("编辑时间")]
        [DataObjectField(false, false, true, 3)]
        [BindColumn(7, "EditTime", "编辑时间", null, "datetime", 3, 0, false)]
        public virtual DateTime EditTime
        {
            get { return _EditTime; }
            set { if (OnPropertyChanging(__.EditTime, value)) { _EditTime = value; OnPropertyChanged(__.EditTime); } }
        }

        private Int32 _Hits;
        /// <summary>点击数</summary>
        [DisplayName("点击数")]
        [Description("点击数")]
        [DataObjectField(false, false, true, 10)]
        [BindColumn(8, "Hits", "点击数", null, "int", 10, 0, false)]
        public virtual Int32 Hits
        {
            get { return _Hits; }
            set { if (OnPropertyChanging(__.Hits, value)) { _Hits = value; OnPropertyChanged(__.Hits); } }
        }

        private Int32 _ID;
        /// <summary>编号</summary>
        [DisplayName("编号")]
        [Description("编号")]
        [DataObjectField(true, true, false, 10)]
        [BindColumn(9, "ID", "编号", null, "int", 10, 0, false)]
        public virtual Int32 ID
        {
            get { return _ID; }
            set { if (OnPropertyChanging(__.ID, value)) { _ID = value; OnPropertyChanged(__.ID); } }
        }
        #endregion

        #region 获取/设置 字段值
        /// <summary>
        /// 获取/设置 字段值。
        /// 一个索引，基类使用反射实现。
        /// 派生实体类可重写该索引，以避免反射带来的性能损耗
        /// </summary>
        /// <param name="name">字段名</param>
        /// <returns></returns>
        public override Object this[String name]
        {
            get
            {
                switch (name)
                {
                    case __.ClassisID: return _ClassisID;
                    case __.UserID: return _UserID;
                    case __.Title: return _Title;
                    case __.Body: return _Body;
                    case __.Tag: return _Tag;
                    case __.CreateTime: return _CreateTime;
                    case __.EditTime: return _EditTime;
                    case __.Hits: return _Hits;
                    case __.ID: return _ID;
                    default: return base[name];
                }
            }
            set
            {
                switch (name)
                {
                    case __.ClassisID: _ClassisID = Convert.ToInt32(value); break;
                    case __.UserID: _UserID = Convert.ToInt32(value); break;
                    case __.Title: _Title = Convert.ToString(value); break;
                    case __.Body: _Body = Convert.ToString(value); break;
                    case __.Tag: _Tag = Convert.ToString(value); break;
                    case __.CreateTime: _CreateTime = Convert.ToDateTime(value); break;
                    case __.EditTime: _EditTime = Convert.ToDateTime(value); break;
                    case __.Hits: _Hits = Convert.ToInt32(value); break;
                    case __.ID: _ID = Convert.ToInt32(value); break;
                    default: base[name] = value; break;
                }
            }
        }
        #endregion

        #region 字段名
        /// <summary>取得文章字段信息的快捷方式</summary>
        public partial class _
        {
            ///<summary>文章分类</summary>
            public static readonly Field ClassisID = FindByName(__.ClassisID);

            ///<summary>作者</summary>
            public static readonly Field UserID = FindByName(__.UserID);

            ///<summary>标题</summary>
            public static readonly Field Title = FindByName(__.Title);

            ///<summary>内容</summary>
            public static readonly Field Body = FindByName(__.Body);

            ///<summary>摘要</summary>
            public static readonly Field Tag = FindByName(__.Tag);

            ///<summary>发表时间</summary>
            public static readonly Field CreateTime = FindByName(__.CreateTime);

            ///<summary>编辑时间</summary>
            public static readonly Field EditTime = FindByName(__.EditTime);

            ///<summary>点击数</summary>
            public static readonly Field Hits = FindByName(__.Hits);

            ///<summary>编号</summary>
            public static readonly Field ID = FindByName(__.ID);

            static Field FindByName(String name) { return Meta.Table.FindByName(name); }
        }

        /// <summary>取得文章字段名称的快捷方式</summary>
        partial class __
        {
            ///<summary>文章分类</summary>
            public const String ClassisID = "ClassisID";

            ///<summary>作者</summary>
            public const String UserID = "UserID";

            ///<summary>标题</summary>
            public const String Title = "Title";

            ///<summary>内容</summary>
            public const String Body = "Body";

            ///<summary>摘要</summary>
            public const String Tag = "Tag";

            ///<summary>发表时间</summary>
            public const String CreateTime = "CreateTime";

            ///<summary>编辑时间</summary>
            public const String EditTime = "EditTime";

            ///<summary>点击数</summary>
            public const String Hits = "Hits";

            ///<summary>编号</summary>
            public const String ID = "ID";

        }
        #endregion
    }

    /// <summary>文章接口</summary>
    public partial interface IDetails
    {
        #region 属性
        /// <summary>文章分类</summary>
        Int32 ClassisID { get; set; }

        /// <summary>作者</summary>
        Int32 UserID { get; set; }

        /// <summary>标题</summary>
        String Title { get; set; }

        /// <summary>内容</summary>
        String Body { get; set; }

        /// <summary>摘要</summary>
        String Tag { get; set; }

        /// <summary>发表时间</summary>
        DateTime CreateTime { get; set; }

        /// <summary>编辑时间</summary>
        DateTime EditTime { get; set; }

        /// <summary>点击数</summary>
        Int32 Hits { get; set; }

        /// <summary>编号</summary>
        Int32 ID { get; set; }
        #endregion

        #region 获取/设置 字段值
        /// <summary>获取/设置 字段值。</summary>
        /// <param name="name">字段名</param>
        /// <returns></returns>
        Object this[String name] { get; set; }
        #endregion
    }
}